﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BakalarskaPraca.Forms.Controls;

namespace BakalarskaPraca.Forms
{
    public partial class SettingsForm : Form
    {
        public class SettingsNode : TreeNode
        {
            private UserControl _ctrl;
            private Panel _panel;
            public SettingsNode(string name, UserControl ctrl, Panel target)
            {
                this.Text = name;
                this._ctrl = ctrl;
                this._panel = target;
                this._ctrl.Width = this._panel.Width;
                this._ctrl.Height = this._panel.Height;
            }

            public void Select()
            {
                if (this._panel.Controls.Count > 0)
                {
                    this._panel.Controls.Clear();
                }
                this._panel.Controls.Add(this._ctrl);
            }
        }

        public SettingsForm()
        {
            InitializeComponent();
            this.SettingsTreeView.Nodes.Add(new SettingsNode("Plant Generation", new PlantGenerationSettingsControl(), this.MainSettingsPanel));
        }

        private void SettingsTreeViewAfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node is SettingsNode)
            {
                SettingsNode settingsNode = (e.Node as SettingsNode);
                settingsNode.Select();
            }
        }

        private void CancelBtnClick(object sender, EventArgs e)
        {
            Properties.Settings.Default.Reload();
            this.Close();
        }

        private void OkBtnClick(object sender, EventArgs e)
        {
            Properties.Settings.Default.Save();
            this.Close();
        }

        private void ApplyBtnClick(object sender, EventArgs e)
        {
            Properties.Settings.Default.Save();
        }
    }
}
